1 // Code written by Ana EchavarrÃa
7 // Maximum base size is 2^16 - 1
8 const int maxN
= 1 << 16;
13 while(cin
>> nBases
>> nDocs
){
14 if (nBases
== 0 and nDocs
== 0) break;
16 for (int i
= 0; i
< maxN
; i
++) length
[i
] = -1;
18 vector
<int> bases(nBases
, 0);
19 for (int b
= 0; b
< nBases
; b
++){
23 bases
[b
] |= 1 << (num
-1);
27 vector
<int> docs(nDocs
, 0);
28 for (int d
= 0; d
< nDocs
; d
++){
32 docs
[d
] |= 1 << (num
-1);
42 for (int i
= 0; i
< bases
.size(); i
++){
43 // Build next document
44 int next
= curr
| bases
[i
];
45 // Check if it has not been visited yet
46 if (length
[next
] >= 0) continue;
47 length
[next
] = length
[curr
] + 1;
52 for (int d
= 0; d
< docs
.size(); d
++){
53 int document
= docs
[d
];
54 if (length
[document
] >= 0) cout
<< length
[document
];
56 if (d
< docs
.size() - 1) cout
<< " ";